home *** CD-ROM | disk | FTP | other *** search
/ Mac Mania 6 / MacMania 6.toast / / Multimedia & Desktop / sk8 / SK8InJava / Code / Actors / DragResizeEventMode.java < prev    next >
Encoding:
Java Source  |  1997-02-27  |  4.2 KB  |  152 lines  |  [TEXT/CWIE]

  1. /*  SK8 © 1997 Apple Computer, Inc.
  2.     This code is protected under the current SK8 License
  3.     See http://sk8.research.apple.com/ for more information
  4.     Apple Research Laboratories
  5. */
  6.  
  7. import java.util.*;
  8. import java.awt.*;
  9.  
  10. class dragresizeeventmode extends eventmode {
  11.     int mouseh = 0;
  12.     int mousev = 0;
  13.     boolean resizeRatherThanDrag = false;
  14.     boolean dispatchDragEvents = false;
  15.     actor myactor = null;
  16.     actor drageventactor = null;
  17.     
  18.     // methods. 
  19.     
  20.     public dragresizeeventmode (actor act, boolean resizep, boolean dragevents) {
  21.         super();
  22.         this.mouseh = Mouse.x;
  23.         this.mousev = Mouse.y;
  24.         this.myactor = act;
  25.         this.drageventactor = null;
  26.         this.resizeRatherThanDrag = resizep;
  27.         this.dispatchDragEvents = dragevents;
  28.     }
  29.     
  30.     public void handleidle (Event e) {
  31.         int newmouseh = Mouse.x;
  32.         int newmousev = Mouse.y;
  33.         if ((newmouseh != mouseh) || (newmousev != mousev)) {
  34.             if (this.resizeRatherThanDrag) {
  35.                 this.myactor.setboundsrect(0,0,newmouseh - mouseh, newmousev - mousev, true, true, false);
  36.             } else {
  37.                 this.myactor.setlocation(newmouseh - mouseh, newmousev - mousev, true, true);
  38.                 //if (dispatchDragEvents == true) {
  39.                 //    if (drageventactor != null) drageventactor.draggingmousewithin(myactor);
  40.                 //    this.changeeventactor(myactorwindow.pointonwhichactor(newmouseh, newmousev, myactor));
  41.                 //}
  42.                 //if (myactor.container() instanceof actor)
  43.                 //    ((actor)myactor.container()).forcefullredraw();
  44.             }
  45.             mouseh = newmouseh;
  46.             mousev = newmousev;
  47.         }
  48.     }
  49.     
  50.     public void handlemousedown (Event e) {
  51.     }
  52.     
  53.     public void handleactivate (Event e, actor oldwindow) {
  54.     }
  55.     
  56.     public void handlemouseup (Event e) {
  57.         if (this.resizeRatherThanDrag) {
  58.             this.myactor.resizedone();
  59.         } else {
  60.             this.myactor.dragged();
  61.             //this.myactor.drop();
  62.         }
  63.         this.myactor.mouseup();
  64.         this.exitmode();
  65.     }
  66.     
  67.     public void handlekeydown (Event e) {
  68.     }
  69.     
  70.     public void handlekeyup (Event e) {
  71.     }
  72.  
  73.     public void resume () {
  74.     }
  75.  
  76.     public void suspend () {
  77.     }
  78.  
  79.     public void activate () {
  80.     }
  81.  
  82.     public void deactivate () {
  83.     }
  84.         
  85.     /*
  86.         //======================================================================
  87.     // Dispatching mouseenter and mouseleave... 
  88.     //======================================================================
  89.  
  90.     
  91.     // call mouseenter on each item in the path from commoncontainer to this (the actor).
  92.     // use recursion to make the reverse calling happen. 
  93.  
  94.     void reverseddispatchmouseenter (actor act, actor commoncontainer) {
  95.         if (act != commoncontainer) {
  96.             if ((act.container() != null) && (commoncontainer != null)) {
  97.                 this.reverseddispatchmouseenter(act.container(), commoncontainer);
  98.                 act.draggingmouseenter(myactor);
  99.             }
  100.         }
  101.     }
  102.     
  103.     // this = the old actor, the one that should get a mouseleave. 
  104.     
  105.     void dispatchmouseenterandleave(actor oldactor, actor newactor) {
  106.         int olddepth = ((actor) oldactor).depth();
  107.         int newdepth = ((actor) newactor).depth();
  108.         actor commoncontainer;
  109.         // if the actor is no longer on the stage, do not send mouseleaves to it. 
  110.         if (newdepth == 0) 
  111.             this.reverseddispatchmouseenter(newactor, sk8.stage);
  112.         else {
  113.             // [1] find common container.
  114.             if (olddepth > newdepth)
  115.                 commoncontainer = ((actor) oldactor).findcommoncontainer(newactor, olddepth - newdepth);
  116.             else 
  117.                 commoncontainer = ((actor) newactor).findcommoncontainer(oldactor, newdepth - olddepth);
  118.             // [2] Dispatch mouseleave (from deepest up).
  119.             while (true) {
  120.                 if ((oldactor == commoncontainer) || (oldactor == null)) break;
  121.                 oldactor.draggingmouseleave(myactor);
  122.                 oldactor = oldactor.container();
  123.             }
  124.             // [3] set the event actor.
  125.             drageventactor = newactor;
  126.             // [4] Dispatch mouseenter (from shallowest up).
  127.             this.reverseddispatchmouseenter(newactor, commoncontainer);
  128.         }    
  129.     }
  130.     
  131.     // When the oldActor was nil, we throw up our arms. We just set the eventActor and
  132.     // dispatch mouseEnter to everything from the Stage up to the new actor.
  133.  
  134.     void justdomouseenters (actor act) {
  135.         // [1] set the event actor.
  136.         drageventactor = act;
  137.         // [2] send the mouse enters.
  138.         this.reverseddispatchmouseenter(act, sk8.stage);
  139.     }
  140.     
  141.     // this is the new event target. 
  142.     
  143.     void changeeventactor (actor act) {
  144.         if (act != null) {
  145.             if (drageventactor != null)
  146.                 this.dispatchmouseenterandleave(drageventactor ,act);
  147.             else
  148.                 this.justdomouseenters(act);
  149.         }
  150.     }
  151.     */
  152. }